package zzjson.rabbitmq.simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import zzjson.rabbitmq.constants.RabbitConstants;
import zzjson.rabbitmq.constants.RabbitRoutingKey;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import static zzjson.rabbitmq.constants.RabbitExchange.SIMPLE_EXCHANGE;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.rabbitmq.simple</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年04月25日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class MyProducer {

	public static void main(String[] args) throws IOException, TimeoutException {

		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost(RabbitConstants.host);
		factory.setPort(RabbitConstants.port);

		factory.setVirtualHost("/");

		factory.setUsername(RabbitConstants.UserName);
		factory.setPassword(RabbitConstants.password);

		Connection connection = factory.newConnection();

		Channel channel = connection.createChannel();

		String msg = "hello mother fuck";


		channel.basicPublish(SIMPLE_EXCHANGE, RabbitRoutingKey.SIMPLEKEY, null, msg.getBytes());
		channel.close();
		connection.close();

	}
}